import { debug } from "util";

//满金额判断
export function validatemBody (rule,value,callback,data) {
    if (!value) {
        return callback(new Error("请输入金额"))
     }else if(!(/^\d+(\.\d{1,2})?$/.test(value))){
        return callback(new Error("非负数且最多两位小数"));
     }else if (rule.field=="discount1.1.value") {
         if(Number(data[1].value)<=Number(data[0].value)) {
             return callback(new Error("二阶必须大于一阶金额"));
         }else{
             callback();
         }
     }else if (rule.field=="discount1.2.value"){
         if(Number(data[2].value)<=Number(data[1].value)) {
             return callback(new Error("三阶必须大于二阶金额"));
         }else {
             callback();
         }
     }else {
         callback();
     }
}
// 减金额判断
const elBody =function (data1, data2, callback, rule) {
    if (rule.field=="discount2.0.value" && Number(data2[0].value/data1[0].value)>=0.8){ //减金额最大为满金额的80%
        return callback(new Error("减金额最大为满金额的80%"))
    }else if (rule.field=="discount2.1.value" && Number(data2[1]&& data2[1].value/data1[1].value)>=0.8) { //减金额最大为满金额的80%
        return callback(new Error("减金额最大为满金额的80%"))
    }else if (rule.field=="discount2.2.value" && Number(data2[2] && data2[2].value/data1[2].value)>=0.8){
        return callback(new Error("减金额最大为满金额的80%"))
    }else{
        callback()
    }
}
export function validatenBody (rule,value,callback,data1,data2) {
    if (!value) {
        return callback(new Error("请输入金额"))
     }else if(!(/^\d+(\.\d{1,2})?$/.test(value))){
        return callback(new Error("非负数且最多两位小数"));
     }else if (rule.field=="discount2.0.value"){
        elBody(data1,data2, callback, rule)
     }else if (rule.field=="discount2.1.value") {
         if(Number(data2[1].value)<=Number(data2[0].value)) {
             return callback(new Error("二阶必须大于一阶金额"));
         }
         elBody(data1,data2, callback, rule)
     }else if (rule.field=="discount2.2.value"){
         if(Number(data2[2].value<=Number(data2[1].value))) {
             return callback(new Error("三阶必须大于二阶金额"));
         }
         elBody(data1,data2, callback, rule)
     }else {
            callback();
     }
}